/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database;

/**
 *
 * @author Y.Yang
 */

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;


public class Database {
   private static final String HOST = "localhost";
   private static final String PORT = "3306";
   private static final String DATABASE = "ualbanybook";
   private static final String USER = "root";
   private static final String PASSWORD = "isaac16";

   protected Connection connection;
   
   public Database() {}

   public void connect()
   {
      try
      {
         // Override the host if DB_SERVER_HOST is set.
         String host = System.getenv("DB_SERVER_HOST");
         if (host == null) host = HOST;

         Class.forName("com.mysql.jdbc.Driver");

         String url =
            "jdbc:mysql://" + host + ":" + PORT + "/" + DATABASE;
         connection =
            DriverManager.getConnection(url, USER, PASSWORD);
      }
      catch (Exception e) { System.err.println(e); }
   }

   public void disconnect()
   {
      try { connection.close(); }
      catch (Exception e) { System.err.println(e); }
   }
   
   
}
   
